How to Concatenate Strings in MS-SQL Server

MS-SQL Server offers two ways to concatenate strings. The first uses the + operator:

select 'Join these ' + 'strings with a number ' + '23';
result
Join these strings with a number 23

Note that you also need to consciously add spaces to make the string readable. For example, in the customer table to join the first and last names of the customers you have to add a single space in the concatenation:

select top 5 first_name + ' ' + last_name as customer_name from customer ;
customer_name
MARY SMITH
PATRICIA JOHNSON
LINDA WILLIAMS
BARBARA JONES
ELIZABETH BROWN

MS-SQL Server also provides the concat function which transforms the nulls into empty strings when concatenating:

select concat('Concat() handles', null, ' nulls better');
result
Concat() handles nulls better

IN THIS PAGE